/*
 * @(#)BaseAction.java 2009-2-24
 * Copyright (c) 2008-2015 by CJK
 * All rights reserved.
 */
package net.beyond.common.struts2;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Validateable;
import com.opensymphony.xwork2.ValidationAware;
import com.opensymphony.xwork2.ValidationAwareSupport;

/**
 * 
 * @author Shmiluyu
 * @version 1.000 2009-2-24
 */
public class BaseAction implements Action, Serializable, Validateable,
		ValidationAware {
	private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
	private static final long serialVersionUID = 1L;
	protected final Logger log = LogManager.getLogger(getClass());
	private String id;
	private String[] ids;
	private PageVO page;
	public static final String INPUT = "input";
	public static final String SUCCESS = "success";
	public static final String ERROR = "error";
	public static final String ADD = "add";
	public static final String DELETE = "delete";
	public static final String UPDATE = "update";
	public static final String LIST = "list";
	public static final String MANAGE = "manage_index";

	/*
	 * @see com.opensymphony.xwork2.Action#execute()
	 */
	public String execute() throws Exception {
		return null;
	}

	/*
	 * @see com.opensymphony.xwork2.Validateable#validate()
	 */
	public void validate() {
	}

	/*
	 * @see
	 * com.opensymphony.xwork2.ValidationAware#addActionError(java.lang.String)
	 */
	public void addActionError(String arg0) {
		validationAware.addActionError(arg0);
	}

	/*
	 * @see
	 * com.opensymphony.xwork2.ValidationAware#addActionMessage(java.lang.String
	 * )
	 */
	public void addActionMessage(String arg0) {
		validationAware.addActionMessage(arg0);
	}

	/*
	 * @see
	 * com.opensymphony.xwork2.ValidationAware#addFieldError(java.lang.String,
	 * java.lang.String)
	 */
	public void addFieldError(String arg0, String arg1) {
		validationAware.addFieldError(arg0, arg1);
	}

	/*
	 * @see com.opensymphony.xwork2.ValidationAware#getActionErrors()
	 */
	public Collection<String> getActionErrors() {
		return validationAware.getActionErrors();
	}

	/*
	 * @see com.opensymphony.xwork2.ValidationAware#getActionMessages()
	 */
	public Collection<String> getActionMessages() {
		return validationAware.getActionMessages();
	}

	/*
	 * @see com.opensymphony.xwork2.ValidationAware#getFieldErrors()
	 */
	public Map<String, List<String>> getFieldErrors() {
		return validationAware.getFieldErrors();
	}

	/*
	 * @see com.opensymphony.xwork2.ValidationAware#hasActionErrors()
	 */
	public boolean hasActionErrors() {
		return validationAware.hasActionErrors();
	}

	/*
	 * @see com.opensymphony.xwork2.ValidationAware#hasActionMessages()
	 */
	public boolean hasActionMessages() {
		return validationAware.hasActionMessages();
	}

	/*
	 * @see com.opensymphony.xwork2.ValidationAware#hasErrors()
	 */
	public boolean hasErrors() {
		return validationAware.hasErrors();
	}

	/*
	 * @see com.opensymphony.xwork2.ValidationAware#hasFieldErrors()
	 */
	public boolean hasFieldErrors() {
		return validationAware.hasFieldErrors();
	}

	/*
	 * @see
	 * com.opensymphony.xwork2.ValidationAware#setActionErrors(java.util.Collection
	 * )
	 */
	public void setActionErrors(Collection<String> arg0) {
		validationAware.setActionErrors(arg0);
	}

	/*
	 * @seecom.opensymphony.xwork2.ValidationAware#setActionMessages(java.util.
	 * Collection)
	 */
	public void setActionMessages(Collection<String> arg0) {
		validationAware.setActionMessages(arg0);
	}

	/*
	 * @see
	 * com.opensymphony.xwork2.ValidationAware#setFieldErrors(java.util.Map)
	 */
	public void setFieldErrors(Map<String, List<String>> arg0) {
		validationAware.setFieldErrors(arg0);
	}

	/**
	 * Convenience method to get the request
	 * 
	 * @return current request
	 */
	protected HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	/**
	 * Convenience method to get the response
	 * 
	 * @return current response
	 */
	protected HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}

	/**
	 * Convenience method to get the session. This will create a session if one
	 * doesn't exist.
	 * 
	 * @return the session from the request (request.getSession()).
	 */
	protected HttpSession getSession() {
		return getRequest().getSession();
	}

	/**
	 * Convenience method to get the ServletContext
	 * 
	 * @return current ServletContext
	 */
	protected ServletContext getCtx() {
		return ServletActionContext.getServletContext();
	}

	/**
	 * ��ȡ�ͻ���IP
	 * 
	 * @return
	 */
	protected String getClientIp() {
		return getRequest().getRemoteHost();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

	public PageVO getPage() {
		return page;
	}

	public void setPage(PageVO page) {
		this.page = page;
	}

}
